 package com.example.tianling.admin.controller;

import com.alibaba.fastjson.JSONObject;
import com.example.tianling.common.utils.R;
import com.example.tianling.entity.ArticleEntity;
import com.example.tianling.entity.CommentEntity;
import com.example.tianling.entity.FeedbackEntity;
import com.example.tianling.entity.UserEntity;
import com.example.tianling.service.ArticleService;
import com.example.tianling.service.CommentService;
import com.example.tianling.service.FeedbackService;
import com.example.tianling.service.UserService;
import com.google.gson.Gson;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Collections;
import java.util.List;

 /**
 * @className: FeedbackController
 * @author: Kyle
 * @date: 2023/8/7 16:43
 **/
@Controller
public class FeedbackController {

    @Autowired
    private FeedbackService feedbackService;

    @Autowired
    private UserService userService;

    @Autowired
    private ArticleService articleService;

    @Autowired
    private CommentService commentService;

     //查看反馈信息type==0为举报，1为反馈
     @PostMapping("/admin/feedbackId")
     @ResponseBody
     public R feedbackId(@RequestBody FeedbackEntity feedbackEntity){
         System.out.println(feedbackEntity);
         FeedbackEntity list = feedbackService.getById(feedbackEntity.getFeedbackId());
         System.out.println(list);
         return R.success(list);
     }

    //查看反馈信息type==0为举报，1为反馈
    @PostMapping("/admin/feedback")
    @ResponseBody
    public R feedback(@RequestBody FeedbackEntity feedbackEntity){
        System.out.println(feedbackEntity);
        List<FeedbackEntity> list = feedbackService.feedbackList(feedbackEntity.getType());
        System.out.println(list);
        return R.success(list);
    }
     @PostMapping("/admin/feedback/processed.do")
     @ResponseBody
     public R Processed(@RequestBody FeedbackEntity feedbackEntity){

         return R.success(feedbackService.toProcessed(feedbackEntity));
     }


     //查看反馈信息type==0为举报，1为反馈
     @PostMapping("/admin/deleteFeedback")
     @ResponseBody
     public R deleteFeedback(@RequestBody String params){
         JSONObject paramsJSONObject = JSONObject.parseObject(params);
         String ls = paramsJSONObject.getString("ls");
         Gson gson = new Gson();
         List<String> list = gson.fromJson(ls, List.class);
         return R.success(feedbackService.toDelete(list));
     }

    //查看是否处理反馈信息列表,0为未处理，1为已处理
    @PostMapping("/admin/feedback/is_processed.do")
    @ResponseBody
    public R isProcessed(@RequestBody FeedbackEntity feedbackEntity){
        List<FeedbackEntity> list = feedbackService.isProcessedList(feedbackEntity.getIsProcessed());
        return R.success(list);
    }

    //查看反馈/举报信息中未处理/已处理的信息
    @PostMapping("/admin/feedback/info.do")//接收type，isProcessed
    @ResponseBody
    public R info(@RequestBody FeedbackEntity feedbackEntity){
        List<FeedbackEntity> list = feedbackService.infoList(feedbackEntity);
        return R.success(list);
    }


}
